package com.order.dao;

import com.order.pojo.Desk;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface DeskDao {
    //初始状态为0(空) 添加桌子，将ID返回
    @Insert("INSERT INTO desk(state) VALUES (0)")
    @Options(useGeneratedKeys = true, keyProperty = "id" ,keyColumn = "id")
    Integer insertDesk(Desk desk);
    //设置某个桌子的状态为满(1) UPDATE desk SET state=1 WHERE id=1;
    @Update("UPDATE desk SET state=1 WHERE id=#{id}")
    Boolean setFull(Integer id);
    //设置某个桌子的状态为空(0)
    @Update("UPDATE desk SET state=0 WHERE id=#{id}")
    Boolean setEmpty(Integer id);
    //查看桌子总数
    @Select("SELECT COUNT(*) FROM desk")
    Integer countDesk();
    //查看空桌子总数 SELECT COUNT(*) FROM desk WHERE state=0;
    @Select("SELECT COUNT(*) FROM desk WHERE state=0")
    Integer countEmptyDesk();
    //查看所有桌子
    @Select("SELECT * FROM desk")
    List<Desk> findDesks();
    //查看所有空的桌子
    @Select("SELECT * FROM desk WHERE state=0")
    List<Desk> findEmptyDesks();
}
